package cn.lnl.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author LNL
 * @date 2021/9/12 14:30
 */
@Configuration
public class GateWayConfig {

    /**
     * 配置了一个id为path_route_1的路由规则
     * 当访问地址http://locahost:9527/guonei时会自动跳转到分发的地址
     * @param builder
     * @return
     */
    @Bean
    public RouteLocator customRouteLocatorBuilder (RouteLocatorBuilder builder) {
        RouteLocatorBuilder.Builder routes = builder.routes();

        routes.route("path_route_1",
                r -> r.path("/guonei")
                        .uri("http://news.baidu.com/guonei")).build();

        return routes.build();
    }

}
